home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / crobots.zip / CROBOTS.DOC < prev    next >
Text File  |  1985-12-13  |  54KB  |  1,783 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.          #####  ######  ####### ######  ####### #######  #####
  19.         #     # #     # #     # #     # #     #    #    #     #
  20.         #       #     # #     # #     # #     #    #    #
  21.         #       ######  #     # ######  #     #    #     #####
  22.         #       #   #   #     # #     # #     #    #          #
  23.         #     # #    #  #     # #     # #     #    #    #     #
  24.          #####  #     # ####### ######  #######    #     #####
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.         (C) Copyright 1985, All rights reserved.
  36.  
  37.         CROBOTS is copyrighted by:
  38.                   
  39.                 Tom Poindexter
  40.                 2903 Winchester Drive
  41.                 Bloomington, Illinois 61701 USA
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  70.  
  71.  
  72.  
  73.         Table of Contents
  74.  
  75.         1.  License agreement and disclaimer of warranty...........2
  76.         2.  Introduction
  77.           2-1.  Description........................................3
  78.           2-2.  Intended audience..................................3
  79.           2-3.  Machine requirements...............................3
  80.           2-4.  User interface.....................................3
  81.         3.  Types of play
  82.                 Single Play........................................4
  83.                 Match Play.........................................4
  84.         4.  Running CROBOTS
  85.           4-1.  Command line options...............................4
  86.           4-2.  Examples...........................................5
  87.         5.  Game Parameters
  88.           5-1.  Battlefield........................................5
  89.           5-2.  Robot offense......................................5
  90.           5-3.  Robot defense......................................6
  91.           5-4.  Disabling robots...................................6
  92.           5-5.  Sample display.....................................7
  93.         6.  CROBOTS CPU............................................8
  94.         7.  CROBOTS C Compiler
  95.           7-1.  Description........................................8
  96.           7-2.  Features missing from standard C...................8
  97.           7-3.  CROBOTS language...................................9
  98.           7-4.  Compiler limits...................................11
  99.           7-5.  Error and warning messages........................11
  100.         8.  CROBOTS C Intrinsic Function Library
  101.                 scan()............................................12
  102.                 cannon()..........................................13
  103.                 drive()...........................................13
  104.                 damage()..........................................13
  105.                 speed()...........................................13
  106.                 loc_x(), loc_y()..................................14
  107.                 rand()............................................14
  108.                 sqrt()............................................14
  109.                 sin(), cos(), tan(), atan().......................14
  110.         9.  CROBOTS C Program Structure 
  111.           9-1.  Structure.........................................15
  112.           9-2.  Sample: "sniper.r"................................15
  113.         10. CROBOTS CPU Architecture
  114.           10-1. Stack.............................................20
  115.           10-2. Link list.........................................21
  116.           10-3. Instruction set...................................22
  117.           10-4. Machine level debugging...........................23
  118.         11. Implementation Notes..................................24
  119.         12. Order Form............................................25
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                 Page 1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  136.  
  137.  
  138.  
  139.  
  140.         1.  License agreement:
  141.  
  142.         You may make copies of this program, manual, and other files and
  143.         give it to your friends, upload it to bulletin boards, or include
  144.         it in the library of a non-profit computer club.
  145.  
  146.         I expressly forbid any for-profit venture from selling this
  147.         software and manual, either separately or as part of a "library"
  148.         diskette.
  149.  
  150.         SUPPORT SHAREWARE!                        
  151.         If you find this software has any value for you, please send a
  152.         contribution.  For contributions of $20 or more, you will receive
  153.         the full source code to CROBOTS on diskette.  Use the order form
  154.         at the end of the documentation.  Your contribution will
  155.         encourage me to enhance the program, by expanding the CROBOTS C
  156.         compiler, adding graphics, sound, etc.
  157.  
  158.         Whether or not you contribute, please share this software with
  159.         others.
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.         DISCLAIMER OF WARRANTY
  168.  
  169.         THIS SOFTWARE AND MANUAL ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
  170.         AND KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED
  171.         TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS OF
  172.         PURPOSE.  THE USER OF THIS SOFTWARE AND MANUAL ASSUME ALL RISKS.
  173.         
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                 Page 2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  202.  
  203.  
  204.  
  205.         2.  Introduction
  206.  
  207.         2-1.  Description
  208.  
  209.         CROBOTS ("see-robots") is a game based on computer programming.
  210.         Unlike arcade type games which require human inputs controlling
  211.         some object, all strategy in CROBOTS must be complete before the
  212.         actual game begins.  Game strategy is condensed into a C language
  213.         program that you design and write.  Your program controls a robot
  214.         whose mission is to seek out, track, and destroy other robots,
  215.         each running different programs.  Each robot is equally equipped,
  216.         and up to four robots may compete at once.  CROBOTS is best
  217.         played among several people, each refining their own robot
  218.         program, then matching program against program.
  219.  
  220.         CROBOTS consists of a C compiler, a virtual computer, and
  221.         battlefield display (text graphics only, monochrome or color).
  222.         The CROBOTS compiler accecpts a limited (but useful) subset of
  223.         the C language.  The C robot programs are aided by hardware
  224.         functions to scan for opponents, start and stop drive mechanisms,
  225.         fire cannons, etc.  After the programs are compiled and loaded
  226.         into separate robots, the battle is observed.  Robots moving,
  227.         missiles flying and exploding, and certain status information are
  228.         displayed on the screen, in real-time.
  229.  
  230.  
  231.         2-2.  Intended audience
  232.  
  233.         CROBOTS will most likely appeal to programmers (especially those
  234.         who think they can write the "best" programs), computer game
  235.         enthusiasts, people wishing to learn the C language, and those
  236.         who are interested in compiler design and virtual computer
  237.         interpreters.
  238.  
  239.  
  240.         2-3.  Machine and software requirements
  241.  
  242.         - IBM-PC, or other close MS-DOS computers that use INT 10H video
  243.           calls 
  244.         - 192k ram 
  245.         - DOS 2.0 or higher 
  246.         - One disk drive 
  247.         - Monochrome or Color/Graphics display 
  248.         - Text editor (PC-DOS Edlin, or your own favorite)
  249.  
  250.  
  251.         2-4.  User interface
  252.  
  253.         CROBOTS does not use menus, windows, pop-ups, or any other
  254.         user-friendly interface.  Since the emphasis is on designing and
  255.         writing robot control programs, CROBOTS is started as a compiler
  256.         might be started, from the DOS command line.
  257.  
  258.  
  259.  
  260.  
  261.                                 Page 3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  268.  
  269.  
  270.  
  271.         3. Types of play
  272.  
  273.         CROBOTS can either run one match (single play), in which the full
  274.         screen, realtime battlefield display is used, or several matches
  275.         (match play), in which only the name of the winner is
  276.         printed after each match.  Single play is the default.  Match
  277.         play is intended to see how robot programs perform on the
  278.         average.   Match play can consume several hours of computer
  279.         time depending on the number of matches and cpu cycle limit, and
  280.         can be run overnight.
  281.          
  282.  
  283.  
  284.         4.  Running CROBOTS
  285.  
  286.         4-1.  Command line options
  287.  
  288.         CROBOTS is started from the DOS prompt:
  289.  
  290.         A>crobots [options] robot-program-1 [robot-program-n] [>file]
  291.         
  292.         Valid options and parameters are:
  293.  
  294.         -c    (opt)     Compile only, and produce virtual machine
  295.                         assembler code and symbol tables.
  296.  
  297.         -d    (opt)     Compile one program, and invoke machine level
  298.                         single step tracing.
  299.  
  300.         -mxxx (opt)     Run a series of matches, were "xxx" is the number
  301.                         of matches.  There should be no spaces between
  302.                         "-m" and the number.  If "-m" is not specified,
  303.                         then the default is to run one match and display
  304.                         the realtime battlefield.
  305.  
  306.         -lxxx  (opt)    Limit the number of machine cpu cycles per match
  307.                         when "-m" is specified.  There should be no
  308.                         spaces between "-l" and the number.  The default
  309.                         cycle limit is 500,000 when -m is specified
  310.  
  311.         robot-programs  (required)
  312.                         The file name of the CROBOTS source program(s).
  313.                         Up to four files may be specified.  If 
  314.                         only one file is specified, it will be "cloned"
  315.                         into another, so that two robots (running the
  316.                         same program) will compete.
  317.                         Any file name may be used, but for consistency 
  318.                         use '.r' as an extension.
  319.  
  320.         >file  (opt)    Use DOS 2.0+ redirection to get a compile
  321.                         listing ("-c" option) or to record matches ("-m"
  322.                         option).
  323.  
  324.  
  325.  
  326.  
  327.                                 Page 4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  334.  
  335.  
  336.  
  337.         4-2.  Examples:
  338.  
  339.                 1) Watch three robots compete with full display:
  340.                         A>crobots robot1.r robot2.r robot3.r 
  341.  
  342.                 2) Compile one robot, and save the listing:
  343.                         A>crobots -c robot1.r >robot1.lst
  344.  
  345.                 3) Debug a robot (first get an assembler code listing,
  346.                    as in example 2:
  347.                         A>crobots -d robot1.r
  348.  
  349.                 4) Run 50 matches, limiting total cpu cycles to 200,000,
  350.                    and save results:
  351.                         A>crobots -m50 -l200000 robot1.r robot2.r >save
  352.        
  353.  
  354.        
  355.         5.  Game parameters
  356.         
  357.         5-1.  Battlefield
  358.  
  359.         The battlefield is a 1,000 by 1,000 meter square.  A wall
  360.         surrounds the perimeter, so that a robot running into the wall
  361.         will incur damage.
  362.  
  363.         The lower left corner has the coordinates x = 0, y = 0; the upper
  364.         right corner has the coordinated x = 999, y = 999.
  365.  
  366.         The compass system is oriented so that due east (right) is 0
  367.         degrees, 90 is north, 180 is west, 270 is south.  One degree
  368.         below due east is 359.
  369.  
  370.  
  371.                          135    90   45
  372.                              \  |  / 
  373.                               \ | /
  374.                         180 --- x --- 0
  375.                               / | \
  376.                              /  |  \ 
  377.                          225   270   315
  378.  
  379.  
  380.         5-2.  Robot offense
  381.  
  382.         The main offensive weapons are the cannon and scanner.  The
  383.         cannon has a range of 700 meters.  There are an unlimited number
  384.         of missiles that can be fired, but a reloading factor limits the
  385.         number of missiles in the air at any one time to two.  The cannon
  386.         is mounted on an independent turret, and therefore can fire any
  387.         direction, 0-359, regardless of robot heading.
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                 Page 5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  400.  
  401.  
  402.  
  403.         The scanner is an optical device that can instantly scan any
  404.         chosen heading, 0-359.  The scanner has a maximum resolution of  
  405.         +/- 10 degrees.  This enables the robot to quickly scan the field
  406.         at a low resolution, then use maximum resolution to pinpoint an
  407.         opponent.
  408.  
  409.  
  410.         5-3.  Robot defense 
  411.  
  412.         The only defense available are the motor drive and status
  413.         registers.  The motor can be engaged on any heading, 0-359, in
  414.         speeds from 0-100 percent of power.  There are acceleration and
  415.         deacceleration factors.  A speed of 0 stops the motor.  Turns can
  416.         be negotiated at speeds of 50% and less, in any direction.  Of
  417.         course, the motor drive can be engaged any time, and is necessary
  418.         on offense when a target is beyond the 700 meter range of the
  419.         cannon.
  420.  
  421.         Certain status registers provide feedback to the robot. The
  422.         primary registers indicate the percent of damage, and current x
  423.         and y locations on the battlefield.  Another register provides
  424.         current drive speed.
  425.  
  426.  
  427.         5-4.  Disabling opponents
  428.  
  429.         A robot is considered dead when the damage reaches 100%.  Percent
  430.         of damage is inflicted as follows:
  431.  
  432.                 2% - collision into another robot (both robots in a    
  433.                      collision receive damage) or into a wall.  A
  434.                      collision also causes the motor drive to disengage,
  435.                      and speed is reduced to 0.
  436.  
  437.                 3% - a missile exploding within a 40 meter radius.
  438.  
  439.                 5% - a missile exploding within a 20 meter radius.
  440.  
  441.                10% - a missile exploding within a 5 meter radius.
  442.  
  443.         Damage is cumulative, and cannot be repaired.  However, a robot
  444.         does not loose any mobility, fire potential, etc. at high damage
  445.         levels.  In other words, a robot at 99% damage performs equally
  446.         as a robot with no damage.
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                 Page 6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  466.  
  467.  
  468.  
  469.         5-5.  Sample display                                
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.                                                           (Status
  477.                                         (x=999,y=999)        blocks)
  478.  
  479.            +------------------------------------+ 1 fubar.r
  480.            |                                    |  D% 015   Sc 218
  481.            |                          \|/ 1     |  Sp 000   Hd 090
  482.            |     (missile exploding)  -#-       | ------------------
  483.            |                          /|\       | 2 snafu.r
  484.         (y |                                    |  D% 050   Sc 275
  485.            |              +        (missiles    |  Sp 100   Hd 180
  486.         a  |                     +   flying)    | ------------------
  487.         x  |   2                                | 3 bimbo.r
  488.         i  |                                    |  D% 000   Sc 045
  489.         s) |                 3                  |  Sp 000   Hd 000
  490.            |                /                   | ------------------
  491.            |          (robots) ----\            | 4 kumquat.r
  492.            |                         4          |  D% 100   Sc 050
  493.            |                                    |  Sp 000   Hd 335
  494.            |                                    | 
  495.            |                                    |
  496.            +------------------------------------+ CPU Cycle: 4500
  497.  
  498.         (x=0,y=0)         (x axis)
  499.  
  500.  
  501.         Each status block shows the file name of the robot, the damage
  502.         incurred, the current scan degrees, and the speed and heading.
  503.         Robots are represented on the field by '1', '2', etc., according
  504.         to the status block position.  The number of elapsed robot cpu
  505.         cycles is shown at the bottom of the status blocks.
  506.  
  507.         The CROBOTS program can be stopped at any time, by using
  508.         Ctrl-Break.
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                 Page 7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  532.  
  533.  
  534.  
  535.         6.  CROBOTS CPU 
  536.  
  537.         The robot cpu is a simple stack-oriented computer.  It operates
  538.         at very slow speeds (on a 4.77MHz 8088 PC with two robots
  539.         running, the average speed is 270 instructions per second, .00027
  540.         mips!!).  The word size is 32 bits, allowing integer values from
  541.         -2,147,483,648 to 2,147,483,647.  There are internal pointer
  542.         registers that manage stack usage, but are not accessable from a
  543.         robot program.  The same is true for an implicit accumulator.
  544.  
  545.         The maximum code space is 1,000 instructions.  All instructions
  546.         are equal in length.  The maximum stack size is 500 words, which
  547.         is used for data and function call/returns.  The stack grows
  548.         upward for data usage, and downward (from the end) for function
  549.         call/returns.  Three words are used for each function call, and
  550.         are release upon the function return.  The data portion and
  551.         call/return portion are managed by separate internal stack
  552.         pointers. 
  553.  
  554.         If the data stack pointer and call/return stack pointer collide,
  555.         a stack overflow occurs.  In this case, the robot is restarted
  556.         at the 'main' function, with the stack reset to all zeroes.
  557.  
  558.         For more information, see the section on machine instructions and
  559.         theory.
  560.  
  561.  
  562.         7.  CROBOTS C compiler
  563.  
  564.         7-1.  Description
  565.  
  566.         The CROBOTS compiler accepts a limited subset of the C language.
  567.         There is no provision for separate compilation, i.e., all modules
  568.         of a program must be in one file.  No preprocessor is provided
  569.         for "#define", "#include", etc.  Identifiers are significant to 7
  570.         characters, although any length may be used.  The compiled
  571.         machine code is loaded into the robot cpu, and cannot be saved.
  572.  
  573.  
  574.         7-2.  Features missing from standard C
  575.  
  576.         Major language features missing from K&R are:  floating point
  577.         variables, structures, unions, pointers, initializers, arrays,
  578.         character data, typedefs, for statment, do..while statement,
  579.         switch..case statement, break, continue, gotos and labels,
  580.         ternary and comma operators, octal and hexadecimal constants, no
  581.         parameters to main(), and all preprocessor directives.
  582.         My apologies to "The C Programming Language" by Brian W.
  583.         Kernighan and Dennis M. Ritchie, Prenctice-Hall, 1978.
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                 Page 8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  598.  
  599.  
  600.  
  601.         7-3.  CROBOTS language
  602.         
  603.         The language features that are present are entirely suitable for
  604.         writing robot control programs.  Basic programming constructs of
  605.         if..then..else, while, and function calls can be used freely.
  606.         Full expression evaluation is also provided, so that statements
  607.         such as: 
  608.                 if ((x = func1(y,1,++z,func2(c))) > 0)
  609.                   a = 0;  
  610.                 else 
  611.                   a = x;
  612.         are perfectly legal.  Ifs and whiles may be nested, and recursion
  613.         is supported.  Variables declared outside a function definition
  614.         are global in scope, whereas variables declared inside a function
  615.         definition are local to that function.
  616.         
  617.  
  618.         The following keywords are recognized:
  619.  
  620.         comments:
  621.         "/* ... */"     comments cannot be nested
  622.  
  623.         constants:
  624.         any decimal digits, optionally preceeded with a '-'
  625.  
  626.          declarations:
  627.         "int"           variable declare
  628.         "long"          same as int
  629.         "auto"          default storage scope, optional
  630.         "register"      legal, but ignored, same as auto
  631.         "function (parms,.....)"  function definition
  632.  
  633.          logic control:
  634.         "if (expr) STMT else STMT"
  635.  
  636.          iteration:
  637.         "while (expr) STMT" 
  638.  
  639.         function return:
  640.         "return"        return 
  641.         "return expr"   return a with value
  642.  
  643.         assignment operators:
  644.         "="             assignment   
  645.         ">>="           assignment shift right
  646.         "<<="           assignment shift left
  647.         "+="            assignment addition
  648.         "-="            assignment subtraction   
  649.         "*="            assignment multiplication   
  650.         "/="            assignment division   
  651.         "%="            assignment modulo   
  652.         "&="            assignment and   
  653.         "^="            assignment exclusive or   
  654.         "|="            assignment inclusive or
  655.  
  656.  
  657.                                 Page 9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  664.  
  665.  
  666.  
  667.  
  668.         bit-wise operators:
  669.         ">>"            shift right
  670.         "<<"            shift left               
  671.         "&"             and
  672.         "!"             unary not
  673.         "~"             unary one's complement
  674.         "^"             exclusive or
  675.         "|"             inclusive or                          
  676.  
  677.         increment/decrement operators:
  678.         "++"            prefix increment, see derivations
  679.         "--"            prefix decrement, see derivations
  680.  
  681.         logical operators:
  682.         "&&"            logical and   
  683.         "||"            logical or    
  684.         "<="            logical less than or equal    
  685.         ">="            logical greater than or equal    
  686.         "=="            logical equal   
  687.         "!="            logical not equal   
  688.         "<"             logical less than   
  689.         ">"             logical greater than   
  690.  
  691.         arithmetic operators:
  692.         "-"             subtraction or unary negation
  693.         "+"             addition   
  694.         "*"             multiplication   
  695.         "/"             division   
  696.         "%"             modulo   
  697.  
  698.         misc:
  699.         ";"             statement terminator or null statement   
  700.         "{ }"           compound statement   
  701.         ","             parameter separator in function definition or call
  702.         "( )"           expression or function definition or call
  703.  
  704.         Precedence and order of evaluation are the same as in K&R.
  705.  
  706.                 Operator                Associativity
  707.                 ()                      left to right
  708.                 ! ~ ++ -- -             right to left
  709.                 * / %                   left to right
  710.                 + -                      "   "    "
  711.                 << >>                    "   "    "
  712.                 < <= => >                "   "    "
  713.                 == !=                    "   "    "
  714.                 &                        "   "    "
  715.                 ^                        "   "    "
  716.                 |                        "   "    "
  717.                 &&                       "   "    "
  718.                 ||                       "   "    "
  719.                 = -= += etc.            right to left
  720.  
  721.  
  722.  
  723.                                 Page 10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  730.  
  731.  
  732.  
  733.         Major derivations from K&R:
  734.  
  735.         -Local variables need not be declared before reference, i.e., any
  736.         undeclared variable will default to a local variable.  
  737.  
  738.         -Postfix increment and decrement ("var++" or "var--") are
  739.         recognized, but the result is the same as prefix
  740.         increment/decrement ("++var").
  741.  
  742.         -Intrinsic function names are reserved.
  743.  
  744.  
  745.         7-4.  Compiler limits
  746.  
  747.         defined functions: 64
  748.         local variables per function: 64
  749.         external variables: 64
  750.         if nest level: 16
  751.         while nest level: 16
  752.  
  753.  
  754.         7-5.  Complier error and warning messages:
  755.  
  756.         The compiler has no error recovery and will stop on the first
  757.         error found.  Sorry.  Warning messages do not stop the compiler.
  758.         
  759.         Error messages
  760.  
  761.         "syntax error" - Any input that results in improper C syntax will
  762.         yield "syntax error", with an indicator pointing to the
  763.         unrecognizable input.
  764.  
  765.         "instruction space exceeded" - compiler tried to generate more
  766.         than 1000 machine instructions.
  767.  
  768.         "symbol pool exceeded" - the maximum local variable, external
  769.         variable, or function definition symbol table was exceeded.
  770.  
  771.         "function referenced but not found" - a function was referenced
  772.         that was not defined in the input file or is not an intrinsic
  773.         function.
  774.  
  775.         "main not defined" - the input file did not define a 'main()'
  776.         function.
  777.  
  778.         "function definition same as intrinsic" - a function was defined
  779.         with the same name as an intrinsic function, which are reserved.
  780.  
  781.         "if nest level exceeded" - more than 16 'if's were nested.
  782.  
  783.         "while nest level exceeded" - more than 16 'while's were nested.
  784.  
  785.         "yacc stack overflow" - the compiler's parser overflowed,
  786.         probably due to complex expressions and/or extreme nesting.
  787.  
  788.  
  789.                                 Page 11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  796.  
  797.  
  798.  
  799.  
  800.         Warning messages
  801.  
  802.         These messages will not cause the compiler to fail, but may cause
  803.         the program to executed unexpectedly.
  804.  
  805.         "unsupported initializer" - variable declares cannot include an
  806.         initializer.  For future releases.
  807.  
  808.         "unsupported break" - the 'break' statement was found and
  809.         ignored.  For future releases.
  810.  
  811.         "n postfix operators" - postfix increment or decrement
  812.         operators were used, and are coerced into prefix expressions.
  813.  
  814.         "n undeclared variables" - one or more variables were implicitly
  815.         declared.
  816.  
  817.         "code utilization: n%" - reports the capacity of machine
  818.         instructions generated.
  819.  
  820.  
  821.  
  822.         8.  CROBOTS C Intrinsic Function Library
  823.  
  824.         The intrinsic function library provides machine level control and
  825.         certain arithmetic functions.  These functions do not consume
  826.         any of the program code space or data stack, except for the three
  827.         words for call/return sequences.  No explicit linking is required
  828.         to use any intrinsic function.
  829.  
  830.  
  831.         scan (degree,resolution)  
  832.  
  833.         The scan() function invokes the robot's scanner, at a specified
  834.         degree and resolution.  scan() returns 0 if no robots are
  835.         within the scan range or a positive integer representing the
  836.         range to the closest robot.  Degree should be within the range
  837.         0-359, otherwise degree is forced into 0-359 by a modulo 360
  838.         operation, and made positive if necessary.  Resolution controls
  839.         the scanner's sensing resolution, up to +/- 10 degrees.
  840.         Examples:
  841.            range = scan(45,0); /* scan 45, with no variance */
  842.            range = scan(365,10); /* scans the range from 355 to 15 */
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                 Page 12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  862.  
  863.  
  864.  
  865.         cannon (degree,range)
  866.  
  867.         The cannon() function fires a missile heading a specified range
  868.         and direction.  cannon() returns 1 (true) if a missile was fired,
  869.         or 0 (false) if the cannon is reloading.  Degree is forced into
  870.         the range 0-359 as in scan().  Range can be 0-700, with greater
  871.         ranges truncated to 700.
  872.         Examples:
  873.            degree = 45;    /* set a direction to test */
  874.            if ((range=scan(degree,2)) > 0) /* see if a target is there */
  875.              cannon(degree,range);  /* fire a missile */
  876.  
  877.  
  878.         drive (degree,speed)
  879.  
  880.         The drive() function activates the robot's drive mechanism, on a 
  881.         specified heading and speed.  Degree is forced into the range
  882.         0-359 as in scan().  Speed is expressed as a percent, with 100 as
  883.         maximum.  A speed of 0 disengages the drive.  Changes in
  884.         direction can be negotiated at speeds of less than 50 percent.
  885.         Examples:
  886.            drive(0,100);  /* head due east, at maximum speed */
  887.            drive(90,0);   /* stop motion */
  888.  
  889.  
  890.         damage()
  891.  
  892.         The damage() function returns the current amount of damage
  893.         incurred.  damage() takes no arguments, and returns the percent
  894.         of damage, 0-99. (100 percent damage means the robot is
  895.         completely disabled, thus no longer running!) 
  896.         Examples:
  897.           d = damage();       /* save current state */
  898.           ; ; ;               /* other instructions */
  899.           if (d != damage())  /* compare current state to prior state */
  900.           {
  901.             drive(90,100);    /* robot has been hit, start moving */
  902.             d = damage();     /* get current damage again */
  903.           } 
  904.  
  905.  
  906.         speed ()
  907.  
  908.         The speed() function returns the current speed of the robot.
  909.         speed() takes no arguments, and returns the percent of speed,
  910.         0-100.  Note that speed() may not always be the same as the last
  911.         drive(), because of acceleration and deacceleration.
  912.         Examples:
  913.           drive(270,100);   /* start drive, due south */
  914.           ; ; ;             /* other instructions */
  915.           if (speed() == 0) /* check current speed */
  916.           {
  917.             drive(90,20); /* ran into the south wall, or another robot*/
  918.           }
  919.  
  920.  
  921.                                 Page 13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  928.  
  929.  
  930.  
  931.  
  932.  
  933.         loc_x ()
  934.         loc_y ()
  935.  
  936.         The loc_x() function returns the robot's current x axis location.
  937.         loc_x() takes no arguments, and returns 0-999.
  938.         The loc_y() function is similar to loc_x(), but returns the
  939.         current y axis position.
  940.         Examples:
  941.            drive (180,50);  /* start heading for west wall */
  942.            while (loc_x() > 20)
  943.              ;              /* do nothing until we are close */
  944.            drive (180,0);   /* stop drive */
  945.  
  946.  
  947.         rand (limit)
  948.  
  949.         The rand() function returns a random number between 0 and limit, 
  950.         up to 32767.
  951.         Examples:
  952.           degree = rand(360);     /* pick a random starting point */
  953.           range = scan(degree,0); /* and scan */
  954.  
  955.  
  956.         sqrt (number)
  957.  
  958.         The sqrt() returns the square root of a number.  Number is made
  959.         positive, if necessary.
  960.         Examples:
  961.            x = x1 - x2;     /* compute the classical distance formula */
  962.            y = y1 - y2;     /* between two points (x1,y1) (x2,y2) */
  963.            distance = sqrt((x*x) - (y*y)); 
  964.  
  965.  
  966.         sin (degree)
  967.         cos (degree)
  968.         tan (degree)
  969.         atan (ratio)
  970.  
  971.         These functions provide trigometric values.  sin(), cos(),
  972.         and tan(), take a degree argument, 0-359, and returns the
  973.         trigometric value times 100,000.  The scaling is necessary since
  974.         the CROBOT cpu is an integer only machine, and trig values are
  975.         between 0.0 and 1.0.  atan() takes a ratio argument that has been
  976.         scaled up by 100,000, and returns a degree value, between -90 and
  977.         +90.  The resulting calculation should not be scaled to the
  978.         actual value until the final operation, as not to lose accuracy.
  979.         See programming examples for usage.
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                 Page 14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  994.  
  995.  
  996.  
  997.         9.  CROBOTS C Program Structure
  998.  
  999.         9-1.  Basic program structure 
  1000.  
  1001.         CROBOTS programs are not unlike other C programs.  The minimum
  1002.         CROBOTS program consist of a function named "main".
  1003.         Additionally, other functions can be defined, along with external
  1004.         variables.
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.         9.2 "sniper.r"
  1013.  
  1014.         The following CROBOTS program is provided as an example.
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023. /* sniper */
  1024. /* strategy: since a scan of the entire battlefield can be done in 90 */
  1025. /* degrees from a corner, sniper can scan the field quickly. */
  1026.  
  1027. /* external variables, that can be used by any function */
  1028. int corner;           /* current corner 0, 1, 2, or 2 */
  1029. int c1x, c1y;         /* corner 1 x and y */
  1030. int c2x, c2y;         /*   "    2 "  "  " */
  1031. int c3x, c3y;         /*   "    3 "  "  " */
  1032. int c4x, c4y;         /*   "    4 "  "  " */
  1033. int s1, s2, s3, s4;   /* starting scan position for corner 1 - 4 */
  1034. int sc;               /* current scan start */
  1035. int d;                /* last damage check */
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.                                 Page 15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1060.  
  1061.  
  1062.  
  1063. /* main */
  1064. main()
  1065. {
  1066.   int closest;        /* check for targets in range */
  1067.   int range;          /* range to target */
  1068.   int dir;            /* scan direction */
  1069.  
  1070.   /* initialize the corner info */
  1071.   /* x and y location of a corner, and starting scan degree */
  1072.   c1x = 10;  c1y = 10;  s1 = 0;
  1073.   c2x = 10;  c2y = 990; s2 = 270;
  1074.   c3x = 990; c3y = 990; s3 = 180;
  1075.   c4x = 990; c4y = 10;  s4 = 90;
  1076.   closest = 9999;
  1077.   new_corner();       /* start at a random corner */ 
  1078.   d = damage();       /* get current damage */
  1079.   dir = sc;           /* starting scan direction */ 
  1080.  
  1081.   while (1) {         /* loop is executed forever */
  1082.  
  1083.     while (dir < sc + 90) {  /* scan through 90 degree range */
  1084.       range = scan(dir,1);   /* look at a direction */
  1085.       if (range <= 700 && range > 0) { 
  1086.         while (range > 0) {    /* keep firing while in range */
  1087.           closest = range;     /* set closest flag */
  1088.           cannon(dir,range);   /* fire! */
  1089.           range = scan(dir,1); /* check target again */
  1090.           if (d + 15 > damage())  /* sustained several hits, */ 
  1091.             range = 0;            /* goto new corner */
  1092.         }
  1093.         dir -= 10;             /* back up scan, in case */
  1094.       }
  1095.  
  1096.       dir += 2;                /* increment scan */
  1097.       if (d != damage()) {     /* check for damage incurred */
  1098.         new_corner();          /* we're hit, move now */
  1099.         d = damage();
  1100.         dir = sc;
  1101.       }
  1102.     }
  1103.  
  1104.     if (closest == 9999) {       /* check for any targets in range */
  1105.       new_corner();             /* nothing, move to new corner */
  1106.       d = damage();
  1107.       dir = sc;
  1108.     } else                      /* targets in range, resume */
  1109.       dir = sc;
  1110.     closest = 9999;
  1111.   } 
  1112.  
  1113. }  /* end of main */
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                 Page 16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1126.  
  1127.  
  1128.  
  1129. /* new corner function to move to a different corner */
  1130. new_corner() {
  1131.   int x, y;
  1132.   int angle;
  1133.   int new;
  1134.  
  1135.   new = rand(4);           /* pick a random corner */
  1136.   if (new == corner)       /* but make it different than the */
  1137.     corner = (new + 1) % 4;/* current corner */
  1138.   else
  1139.     corner = new;
  1140.   if (corner == 0) {       /* set new x,y and scan start */
  1141.     x = c1x; 
  1142.     y = c1y; 
  1143.     sc = s1;
  1144.   } 
  1145.   if (corner == 1) {
  1146.     x = c2x; 
  1147.     y = c2y; 
  1148.     sc = s2;
  1149.   }
  1150.   if (corner == 2) {
  1151.     x = c3x; 
  1152.     y = c3y; 
  1153.     sc = s3;
  1154.   }
  1155.   if (corner == 3) { 
  1156.     x = c4x; 
  1157.     y = c4y; 
  1158.     sc = s4;
  1159.   }
  1160.  
  1161.   /* find the heading we need to get to the desired corner */
  1162.   angle = plot_course(x,y);
  1163.  
  1164.   /* start drive train, full speed */
  1165.   drive(angle,100);
  1166.  
  1167.   /* keep traveling until we are within 100 meters */
  1168.   /* speed is checked in case we run into wall, other robot */
  1169.   /* not terribly great, since were are doing nothing while moving */
  1170.  
  1171.   while (distance(loc_x(),loc_y(),x,y) > 100 && speed() > 0)
  1172.     ;
  1173.  
  1174.   /* cut speed, and creep the rest of the way */
  1175.  
  1176.   drive(angle,20);
  1177.   while (distance(loc_x(),loc_y(),x,y) > 10 && speed() > 0)
  1178.     ;
  1179.  
  1180.   /* stop drive, should coast in the rest of the way */
  1181.   drive(angle,0); 
  1182. }  /* end of new_corner */
  1183.  
  1184.  
  1185.                                 Page 17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1192.  
  1193.  
  1194.  
  1195. /* classical pythagorean distance formula */
  1196. distance(x1,y1,x2,y2)
  1197. int x1;
  1198. int y1;
  1199. int x2;
  1200. int y2;
  1201. {
  1202.   int x, y;
  1203.  
  1204.   x = x1 - x2;
  1205.   y = y1 - y2;
  1206.   d = sqrt((x*x) + (y*y));
  1207.   return(d);
  1208. }
  1209.  
  1210. /* plot course function, return degree heading to */
  1211. /* reach destination x, y; uses atan() trig function */
  1212. plot_course(xx,yy)
  1213. int xx, yy;
  1214. {
  1215.   int d;
  1216.   int x,y;
  1217.   int scale;
  1218.   int curx, cury;
  1219.  
  1220.   scale = 100000;  /* scale for trig functions */
  1221.   curx = loc_x();  /* get current location */
  1222.   cury = loc_y();
  1223.   x = curx - xx;
  1224.   y = cury - yy;
  1225.  
  1226.   /* atan only returns -90 to +90, so figure out how to use */
  1227.   /* the atan() value */
  1228.  
  1229.   if (x == 0) {      /* x is zero, we either move due north or south */
  1230.     if (yy > cury)
  1231.       d = 90;        /* north */
  1232.     else
  1233.       d = 270;       /* south */
  1234.   } else {
  1235.     if (yy < cury) {
  1236.       if (xx > curx)
  1237.         d = 360 + atan((scale * y) / x);  /* south-east, quadrant 4 */
  1238.       else
  1239.         d = 180 + atan((scale * y) / x);  /* south-west, quadrant 3 */ 
  1240.     } else {
  1241.       if (xx > curx)
  1242.         d = atan((scale * y) / x);        /* north-east, quadrant 1 */
  1243.       else
  1244.         d = 180 + atan((scale * y) / x);  /* north-west, quadrant 2 */
  1245.     }
  1246.   }
  1247.   return (d);
  1248. }
  1249.  
  1250.  
  1251.                                 Page 18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1258.  
  1259.  
  1260.  
  1261.     
  1262.  
  1263.  
  1264.         Notes:  The distance() and plot_course() routines are
  1265.         quite handy.  Save them for your programs.  Also, note that the
  1266.         main scan routine will "back up" a few degrees after a target has
  1267.         been found and fired upon.  This should catch robots trying to
  1268.         flee away from the direction you are scanning.  If the target
  1269.         moves the other way, the normal scan increment will find it.
  1270.  
  1271.         See the other sample CROBOTS program files.
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.                                 Page 19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1324.  
  1325.  
  1326.  
  1327.  
  1328.         10.  CROBOTS CPU Architecture and Theory
  1329.  
  1330.         This information is provided if you need to use the debug
  1331.         facility, or are curious about the virtual machine interpreter.
  1332.         Don't bother reading this section if you not so inclined; it is
  1333.         not needed for normal play.
  1334.  
  1335.  
  1336.         10-1.  Stack usage:
  1337.  
  1338.         That stack is controlled implicitly by several pointers.  Stack
  1339.         pointers are not accessable through machine instructions.  Most
  1340.         instructions will either push data onto the stack, or pop data
  1341.         off the stack.  The stack is used from the bottom up (low memory)
  1342.         for data and temporary storage, and is used from the top down
  1343.         (high memory) for saving stack pointers and the program counter
  1344.         on function call/return.
  1345.  
  1346.         External (global) variables are allocated at the very bottom of
  1347.         the stack, and the local mark pointer for 'main' starts just
  1348.         after the externals.  External variables are addressed from the
  1349.         beginning of the stack, by offset.
  1350.          
  1351.         When a function is called (including 'main'), the stack pointer
  1352.         is marked (local mark) and is increased by the number of local
  1353.         variables needed for that function.  Local variables are
  1354.         addressed relative to the local mark, by offsets.  All
  1355.         calculations, function calls, and constants are pushed on and
  1356.         popped off the stack as needed (temporary mark or top of stack).
  1357.         
  1358.         A function call also saves its current stack pointers (local
  1359.         variable mark and frame mark) and program counter.  This
  1360.         return information grows from the top down.
  1361.  
  1362.         Arguments are passed to functions by value.  The first argument
  1363.         in a function call becomes the first local variable for the
  1364.         called function.  Consider the following:
  1365.  
  1366.         main() {               /* main has three local variables: */
  1367.           int a, b, c;
  1368.           ....;
  1369.           sub1 (a,b/2,c+1);    /* call sub1, and pass arguments */
  1370.           ....;
  1371.         }
  1372.  
  1373.         sub1 (x,y,z)           /* sub1 takes three parameters and */
  1374.         int x, y, z; {         /* has one local variable */
  1375.           int result;
  1376.           result = x + y + z;
  1377.           return (result);
  1378.         }
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                 Page 20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1390.  
  1391.  
  1392.  
  1393.         The main() function allocates three local variables on the stack,
  1394.         sets its local mark at 'a', and sets the temporary stack pointer
  1395.         beyond the locals.  Just before sub1() is called, the value of
  1396.         'a' is pushed, followed by the result of 'b/2', and 'c+1'.  When
  1397.         sub1() is called, it sets its local mark where the value of 'a'
  1398.         is, so that 'a' is know as 'x' in func1(), likewise 'b/2'
  1399.         is known as 'y' and 'c+1' is known as 'z'.  Sub1() also
  1400.         allocates one more word for 'result', and sets the temporary mark
  1401.         after the storage for 'result'.
  1402.  
  1403.  
  1404.         The following diagram illustrates the stack usage:
  1405.  
  1406.                 +------------+   <-- end of stack, high memory
  1407.                 |main return |   <-- return info for main
  1408.                 +------------+       (frame,ip,local mark)
  1409.                 |sub1 return |   <-- return info for sub1
  1410.                 +------------+       (etc.)
  1411.                 |     |      |
  1412.                 |     v      |   <-- additional function call return
  1413.                 |            |       info grow downwards
  1414.                 |            |
  1415.                 |            |
  1416.                 |            |
  1417.                 |     ^      |   <-- additional function calls and
  1418.                 |     |      |       expressions grow upwards
  1419.                 |expressions |
  1420.                 +------------+   <-- temporary mark (top of stack)
  1421.                 |sub1 locals |
  1422.                 +------------+   <-- local mark: sub1 function
  1423.                 |main locals |
  1424.                 +------------+   <-- local mark: main function
  1425.                 |            |
  1426.                 | Externals  |
  1427.                 |            |
  1428.                 +------------+   <-- beginning of stack
  1429.  
  1430.  
  1431.         10-2.  Link list 
  1432.  
  1433.         The link list is a list built by the compiler that contains
  1434.         the names and link information of the functions within the
  1435.         program.  The link information contains the starting location of
  1436.         the function within the code, the number of parameters, and the
  1437.         number of other local variables within the function.  The link
  1438.         list cannot be accessed by the user program.
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.                                 Page 21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1456.  
  1457.  
  1458.  
  1459.  
  1460.         10-3.  Instruction set
  1461.  
  1462.         The CROBOTS cpu has 10 instructions.  Each instruction occupies
  1463.         the same amount of storage, with or without operands.
  1464.  
  1465.         FETCH offset (external | local) - Fetch will retrieve a word from
  1466.         either the external variable pool or the local variable pool and
  1467.         push it onto the stack.  The offset has its high-bit set (or'ed
  1468.         with 0x8000) if it is an external (offset from the beginning of
  1469.         the stack), otherwise it is a local (offset from the local
  1470.         variable mark).  See STORE.
  1471.  
  1472.         STORE offset (external | local), opcode - Store pops the top two
  1473.         items, applies the arithmetic opcode to the two operands, 
  1474.         pushes the result on the top of the stack and stores it in the
  1475.         variable referenced by the offset.  Offsets are either external
  1476.         or local, according to the method described in Fetch.  The result
  1477.         of the opcode is left on the stack.  See FETCH and BINOP.
  1478.  
  1479.         CONST k - Const will push a constant onto the stack.
  1480.  
  1481.         BINOP opcode - Binop will pop the top two items as top of stack =
  1482.         y, next to top of stack as x, apply the arithmetic opcode as 
  1483.         (x opcode y), and push the result on the stack.  Opcodes are
  1484.         decimal representations of 'C' operators such as '+', '/',
  1485.         '>=', etc.  See STORE.
  1486.  
  1487.         FCALL link-offset - Fcall performs a high level function call
  1488.         facility.  The link-offset operand specifies an entry in the link
  1489.         list table.  Fcall pushes its return information:  the next
  1490.         instruction counter and the current local variable mark.  A new
  1491.         local variable mark and temporary mark (top of stack pointer) is
  1492.         set.  The cpu then branches to the first instruction of the
  1493.         function.  See RETSUB and FRAME.
  1494.  
  1495.         RETSUB - Retsub returns from a function, leaving the return value
  1496.         on the top of the stack.  Retsub restores the previous local
  1497.         variable pool, the next instruction counter, and re-adjusts the
  1498.         stack frame to the point just before the call.  The C
  1499.         compiler generates code to return a dummy value if the
  1500.         function does not explicitly return one. See FCALL and FRAME.
  1501.  
  1502.         BRANCH instruction - Branch pops the top of the stack and
  1503.         branches to the instruction if the value is zero.  The next
  1504.         sequential instruction is executed if the value is
  1505.         anything other than zero.
  1506.  
  1507.         CHOP - Chop discards the top of the stack by popping it into
  1508.         obilvion.
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                 Page 22
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1522.  
  1523.  
  1524.  
  1525.         FRAME - Frame facilitates fcall/retsub by saving the current top
  1526.         of stack pointer (temporary mark) in anticipation of a fcall
  1527.         statement. The top of stack pointer is saved in the call/return
  1528.         stack as a frame marker.  See FCALL and RETSUB.
  1529.  
  1530.         NOP - No operation.  Is used as a mark indicating the end of
  1531.         code.
  1532.  
  1533.  
  1534.         10-4. Machine level debugging
  1535.  
  1536.         Debug mode is used to trace by single stepping machine
  1537.         instructions.  Use this only if you need to see your program
  1538.         execute, or are just curious.
  1539.  
  1540.         First, get a listing on paper of a compile with full information
  1541.         by using the '-c' option:
  1542.                 A>crobots -c yourpgm.r >prn:
  1543.  
  1544.         Next, start CROBOTS again with the '-d' flag:
  1545.                 A>crobots -d yourprm.r
  1546.  
  1547.         Your robot will be placed randomly in the field, and a target
  1548.         robot will be placed at the center of the field (x=500,y=500) 
  1549.         so your robot program can find and shoot at a target.
  1550.  
  1551.         The virtual machine interpreter will single step through your
  1552.         program (machine instructions, that is).  At every instruction,
  1553.         an machine instruction is disassembled, and the top of stack
  1554.         pointer and value are printed.  The top of stack and value are
  1555.         after the results of the instruction.  Other information may 
  1556.         also be printed, such as function calls searching the link list,
  1557.         etc.
  1558.  
  1559.         On every step, you are prompted "d,h,q,<cr>:".  Entering 'd' will
  1560.         dump external and local variable pools, as well as vital
  1561.         information of your robot:  coordinates, heading, speed, damage,
  1562.         etc., and the status of any missiles your robot may have fired.
  1563.         Entering 'h' will simulate your robot taking a 10% damage hit, so
  1564.         you can check damage detection, etc.  Entering 'q' will quit the
  1565.         program immediately, and return you to DOS.  A carriage return
  1566.         alone will continue the stepping process.  All responses
  1567.         ('d','h', or 'q') should be in lower case only.  You should refer
  1568.         to the compile listing for offsets into the external and local
  1569.         variable pools, C code, etc.
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.                                 Page 23
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1588.  
  1589.  
  1590.  
  1591.  
  1592.         11.  Implemetation notes
  1593.  
  1594.         CROBOTS is written entirely in 'C'.  The compiler section was
  1595.         developed with the aid of the Unix* (TM) programs 'yacc' and
  1596.         'lex'.  Yacc (yet another compiler-compiler) accepts a 'grammar',
  1597.         which describes the CROBOTS 'C' language.  Yacc produces a 'C'
  1598.         function known as a parser.  The parser is the heart of the
  1599.         compiler, recognizing vaild 'C' constructs.  Lex (lexical
  1600.         analyzer) accepts a list of token combinations, and produces a
  1601.         'C' function to scan the compiler input for the tokens.  The yacc
  1602.         generated parser, yyparse(), repeatedly calls the lex generated
  1603.         analyzer, yylex(), to process the source program.  The initial
  1604.         screen display routines were developed with the 'curses' screen
  1605.         library.
  1606.  
  1607.         The 'C' source code was then ported to MS-DOS** (TM), and
  1608.         recompiled using the Lattice*** (TM) 2.15E compiler, using the
  1609.         'small' memory model.  The screen display functions were
  1610.         modified to use 'int86()', accessing the rom INT 10H cursor
  1611.         postitioning functions in the IBM-PC bios.
  1612.  
  1613.         * Unix is a trademark of Bell Telephone Laboratories.
  1614.         ** MS-DOS is a trademark of Microsoft, Inc.
  1615.         *** Lattice is a trademark of Lattice, Inc.
  1616.         **** IBM is a trademark of International Business Machines, Inc.
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                 Page 24
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.         CROBOTS Order Form:
  1660.  
  1661.         +------------------------------------------------------------+
  1662.         | 1. Complete and sign the source code license.              |
  1663.         |                                                            |
  1664.         | 2. Send this completed form along with $20 check or        | 
  1665.         |    money order to:                                         |
  1666.         |                                                            |
  1667.         |       Tom Poindexter                                       |
  1668.         |       2903 Winchester Drive                                |
  1669.         |       Bloomington, Illinois 61701                          |
  1670.         |                                                            |
  1671.         |   -For orders outside the U.S., add an additional $5, and  |
  1672.         |    enclose  an international money order, payable in       |
  1673.         |    U.S. currency.                                          | 
  1674.         |                                                            |
  1675.         |                                                            |
  1676.         |                                                            |
  1677.         |  _________________________________________                 |
  1678.         |  Name                                                      |
  1679.         |                                                            |
  1680.         |  _________________________________________                 | 
  1681.         |                                                            |
  1682.         |  _________________________________________                 |
  1683.         |  Address                                                   |
  1684.         |                                                            |
  1685.         |                                                            |
  1686.         |  ______________________   ________  ____________           | 
  1687.         |  City                     State     Zip                    |
  1688.         |                                                            | 
  1689.         |                                                            |
  1690.         |  Source code license:                                      |
  1691.         |  Source code to CROBOTS is provided for personal use only. |
  1692.         |  You may incorporate portions of CROBOTS into your own     |
  1693.         |  programs.                                                 |
  1694.         |                                                            |
  1695.         |  I agree not to distribute CROBOTS source code to anyone   |
  1696.         |  without prior written permission from the copyright       |
  1697.         |  holder, whether a fee is charged or not.                  |
  1698.         |                                                            |
  1699.         |                                                            |
  1700.         |  ________________________________________   ______________ |
  1701.         |  Signature                                  Date           |
  1702.         |                                                            |
  1703.         +------------------------------------------------------------+
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.                                 Page 25
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.         CROBOTS (C) Copyright 1985 by Tom Poindexter.
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.                                 Page 26
  1780.  
  1781.  
  1782.  
  1783.